using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace gpcx
{
    public partial class SettingFrm : Form
    {
        public SettingFrm(List<ValueTuple<string,string>> param)
        {
            InitializeComponent();
            var codes = (ConfigManager.GetAppSettingsKeyValue("gpdm")??"").Split(',');
            var refTime = ConfigManager.GetAppSettingsKeyValue("refTime") ?? "10";
            trackBar1.Value = int.Parse(refTime);
            foreach (var code in codes)
            {
                if (param.Any(o => o.Item1 == code))
                    listView1.Items.Add(code + "-" + param.First(o => o.Item1 == code).Item2);
                else
                    listView1.Items.Add(code);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var codestring = "";
            foreach (ListViewItem item in listView1.Items)
            {
                if(item.Text.Length >= 10)
                    codestring += item.Text.Split('-')[0] + ",";
            }
            ConfigManager.UpdateSetting("gpdm", codestring.TrimEnd(','));
            ConfigManager.UpdateSetting("refTime", trackBar1.Value.ToString());
            Close();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            foreach(ListViewItem item in listView1.SelectedItems)
            {
                listView1.Items.Remove(item);
            }
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            listView1.Items.Add("s_sh");
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            listView1.Items.Add("s_sz");
        }
    }
}
